﻿using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2025-05-15
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 工位表
    /// </summary>
    [Verify]
    [Route("business/CksWorkStation")]
    [ApiExplorerSettings(GroupName = "business")]
    public class CksWorkStationController : BaseController
    {
        /// <summary>
        /// 工位表接口
        /// </summary>
        private readonly ICksWorkStationService _CksWorkStationService;

        public CksWorkStationController(ICksWorkStationService CksWorkStationService)
        {
            _CksWorkStationService = CksWorkStationService;
        }

        /// <summary>
        /// 查询工位表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "cksworkstation:list")]
        public IActionResult QueryCksWorkStation([FromQuery] CksWorkStationQueryDto parm)
        {
            var response = _CksWorkStationService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询工位表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "cksworkstation:query")]
        public IActionResult GetCksWorkStation(int Id)
        {
            var response = _CksWorkStationService.GetInfo(Id);

            var info = response.Adapt<CksWorkStationDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加工位表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "cksworkstation:add")]
        [Log(Title = "工位表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddCksWorkStation([FromBody] CksWorkStationDto parm)
        {
            var modal = parm.Adapt<CksWorkStation>().ToCreate(HttpContext);

            var response = _CksWorkStationService.AddCksWorkStation(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新工位表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "cksworkstation:edit")]
        [Log(Title = "工位表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateCksWorkStation([FromBody] CksWorkStationDto parm)
        {
            var modal = parm.Adapt<CksWorkStation>().ToUpdate(HttpContext);
            var response = _CksWorkStationService.UpdateCksWorkStation(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除工位表
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "cksworkstation:delete")]
        [Log(Title = "工位表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteCksWorkStation([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_CksWorkStationService.Delete(idArr));
        }

    }
}